package com.teamclub.domain.system;

import io.ebean.Ebean;
import io.ebean.Finder;
import io.ebean.Model;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * Created by ilkkzm on 17-9-15.
 */
@Entity
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class AppOrgArch extends Model{
    @Id
    private Integer id;
    private String organNo;
    private String archCode;
    private String archName;
    private Integer level;

    @Transient
    private List<AppOrgArch> children = Lists.newArrayList();

    public static Finder<Integer, AppOrgArch> finder = new Finder<>(AppOrgArch.class);

    public List<AppOrgArch> getChildren() {
        return Ebean.find(AppOrgArch.class).where()
                .eq("organNo", this.organNo)
                .eq("level", this.level + 1)
                .like("archCode", this.archCode + "%").findList();
    }

}
